package com.niit.mall.product.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.niit.mall.common.domain.dto.PageDTO;
import com.niit.mall.product.domain.po.Brand;
import com.niit.mall.product.domain.query.BrandQuery;
import com.niit.mall.product.domain.vo.BrandVO;
import com.niit.mall.product.mapper.BrandMapper;
import com.niit.mall.product.service.IBrandService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: pardo_mall_backend
 * @BelongsPackage: com.niit.mall.product.service.impl
 * @Author: ChuXuan
 * @CreateTime: 2025-06-08  01:09
 * @Description: 品牌服务实现类
 * @Version: 1.0
 */
@Service
@RequiredArgsConstructor
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements IBrandService {

    private final BrandMapper brandMapper;

    /**
     * 查寻品牌信息
     * @return 品牌信息列表
     */
    @Override
    public List<Brand> queryBrand() {
        return brandMapper.queryBrand();
    }

    /**
     * 查询品牌信息VO
     * @return 品牌信息VO列表
     */
    @Override
    public List<BrandVO> queryBrandVO() {
        return brandMapper.queryBrandVO();
    }

    /**
     * 查询品牌信息分页
     * @param query 查询参数
     * @return 品牌信息分页
     */
    @Override
    public PageDTO<BrandVO> queryBrandByPage(BrandQuery query) {
        // 获取分页参数
        Boolean isAsc = query.getIsAsc();
        String sortBy = query.getSortBy();

        Page<Brand> page = query.toMpPage(sortBy, isAsc);

        Page<Brand> brandList = lambdaQuery()
                .page(page);

        return PageDTO.of(brandList, BrandVO.class);
    }
}
